package com.test.aware;

import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Service;

@Service
public class AwareService implements BeanNameAware, ResourceLoaderAware {

	private String beanName;
	private ResourceLoader resourceLoader;
	public void setBeanName(String arg0) {
		// TODO Auto-generated method stub
		this.beanName = arg0;
	}

	public void setResourceLoader(ResourceLoader arg0) {
		// TODO Auto-generated method stub
		this.resourceLoader = arg0;
	}

	public void awareStuff() {
		System.out.println("beanName = " + beanName);
		Resource resource = resourceLoader.getResource("classpath:com/test/aware/f.txt");
		try {
			System.out.println("resourceLoader = " + IOUtils.toString(resource.getInputStream()));
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}
}
